package com.lixin.smartclassroom.ui.home.tab2.activity

import com.github.mikephil.charting.components.XAxis
import com.github.mikephil.charting.data.RadarData
import com.github.mikephil.charting.data.RadarDataSet
import com.github.mikephil.charting.data.RadarEntry
import com.github.mikephil.charting.formatter.IndexAxisValueFormatter
import com.github.mikephil.charting.utils.ColorTemplate
import com.lixin.smartclassroom.bean.EvaluationQuestionsDto
import com.lixin.smartclassroom.bean.WeiduBean
import com.lixin.smartclassroom.databinding.ActivityGroupScoreDetailBinding
import com.lixinkeji.base.BaseActivity
import com.lixinkeji.extension.getIntentSerializable
import com.lixinkeji.extension.getIntentString
import com.lixinkeji.extension.onClick
import com.lixinkeji.extension.start
import com.lwb.radarchart.RadarChartView


/**
 * Description
 * Author: lwc
 * Date:2023/12/8 14:31
 */
class GroupScoreDetailAct : BaseActivity<ActivityGroupScoreDetailBinding>() {
    override fun getViewBinding() = ActivityGroupScoreDetailBinding.inflate(layoutInflater)

    override fun topBarHide() = false
    override fun startPadding() = true
    override fun title() = "得分详情"

    private val xAxisValue: List<String> = ArrayList() //X轴数据源

    private lateinit var weiduList: ArrayList<WeiduBean>

    private var groupid = ""

    override fun iniView() {
        groupid = getIntentString("groupid")
        weiduList = getIntentSerializable("weiduList")
//        initRadarChart()
        initRadarChartView()

    }

    override fun onClick() {
        binding.radarChartView.onClick {
            start(TaskDetailAct::class.java) {
                putExtra("groupid", groupid)
            }
        }
    }

    private fun initRadarChartView() {
        binding.apply {
            for (i in 0 until weiduList.size) {
                radarChartView.insertType(
                    weiduList[i].name,
                    weiduList[i].totalsource?.toDouble()!!.toInt(),
                    100
                )
            }

            val config = RadarChartView.Config()
                .setMaxLevel(5)
                .setCenterPointRadius(5)
                .setChartWidget(0.8f)
                .setFillColor(-0xd97beb)
                .setSecondFillColor(-0x32d9da)
                .setValueLineSize(1)
                .setValuePointRadius(5)
                .setBackgroundColor(-0x7767a9eb)
                .setTextColor(-0x7767a9eb)
                .setTextSize(40)
                .setCanScroll(false)
                .setCanFling(false)
                .setValueBackgroundAlpha(0.2f)
                .setTextPosition(1.1f)
                .setPointRadius(2)
            radarChartView.setConfig(config)

        }
    }

    private fun initRadarChart() {
        binding.apply {
            radarChart.description.isEnabled = true

            val xAxis = radarChart.xAxis
            xAxis.position = XAxis.XAxisPosition.BOTTOM
            xAxis.setDrawGridLines(false)
            xAxis.setDrawLabels(false)
            xAxis.granularity = 1f
            xAxis.textSize = 10f
            xAxis.labelCount = xAxisValue.size
            xAxis.setCenterAxisLabels(true) //设置标签居中
            xAxis.valueFormatter = IndexAxisValueFormatter(xAxisValue)

            val radarEntries: MutableList<RadarEntry> = ArrayList()
            radarEntries.add(RadarEntry(80f))
            radarEntries.add(RadarEntry(85f))
            radarEntries.add(RadarEntry(90f))
            radarEntries.add(RadarEntry(70f))

            val radarDataSet = RadarDataSet(radarEntries, "数据一")
// 实心填充区域颜色
// 实心填充区域颜色
            radarDataSet.fillColor = ColorTemplate.VORDIPLOM_COLORS[0]
// 是否实心填充区域
// 是否实心填充区域
            radarDataSet.setDrawFilled(true)
            val radarData = RadarData(radarDataSet)
            radarChart.data = radarData

        }

    }

}